package cn.itsource.ymcc;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import com.alipay.easysdk.kernel.util.ResponseChecker;
import com.alipay.easysdk.payment.page.models.AlipayTradePagePayResponse;
//
//@RunWith(SpringRunner.class)
//@SpringBootTest(classes = PayApp.class)
public class Mytest {
    public static void main(String[] args) throws Exception {
        // 1. 设置参数（全局只需设置一次）
        Factory.setOptions(getOptions());
        try {
            // 2. 发起API调用（以创建当面付收款二维码为例）
            AlipayTradePagePayResponse response = Factory.Payment.Page()
                    .pay("Apple iPhone11 128G", "2234567890", "5799.00","http://www.baidu.com");
            // 3. 处理响应或异常
            if (ResponseChecker.success(response)) {
                System.out.println(response.getBody());
            } else {
                System.err.println("调用失败，原因：" + response.getBody() + "，" + response.body);
            }
        } catch (Exception e) {
            System.err.println("调用遭遇异常，原因：" + e.getMessage());
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    private static Config getOptions() {
        Config config = new Config();
        config.protocol = "https";
        config.gatewayHost = "openapi-sandbox.dl.alipaydev.com";
        config.signType = "RSA2";
        config.appId = "9021000123601841";
        // 为避免私钥随源码泄露，推荐从文件中读取私钥字符串而不是写入源码中
        config.merchantPrivateKey = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCwpOdVrWOKON3s8ec6/is4j/SR4UzIN8LVxoDSnvTApMe+J8ArIulFqEozpPRtHEHezBKIkLVj/c0bMWwTNTFHLJllyR32+Z0H7t5WUBTskoldcv3Vwfps/rZJG1KMFRl4lxFJstjzbFd1xpXz8smsvw4dy5Lw2Vt//SbNfdrxfPb2XRI/L0/ZzfD+wBVAaclCyTLLjdzMlP65ZbXpPuLExdoytrDNSiFw7dKQAo63O4NxXPS0Pm5Fn7MapDiQcY3DpjGhdoLcm2lU9SWDM3GuPNQxSupafMxZ1NzhRx7tENmK6iNUEWF7KelAmIHtMY2ZyeWZRhRZvc8Iup1NlhgzAgMBAAECggEBAJbQlDpQSVYv6zpr5nI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ZHBNhF+QnpL5s/YyfJv4VAap4ITPl93EHLUomk2xYFzNBoZ9Tl94dD24YbGWbJuWZIYyTixUfjlYJBBMesPsVcYv/ZMV4OpVJ1M/0NtUWs7wP+f6I8";
        //注：证书文件路径支持设置为文件系统中的路径或CLASS_PATH中的路径，优先从文件系统中加载，加载失败后会继续尝试从CLASS_PATH中加载
//            config.merchantCertPath = "<-- 请填写您的应用公钥证书文件路径，例如：/foo/appCertPublicKey_2019051064521003.crt -->";
//            config.alipayCertPath = "<-- 请填写您的支付宝公钥证书文件路径，例如：/foo/alipayCertPublicKey_RSA2.crt -->";
//            config.alipayRootCertPath = "<-- 请填写您的支付宝根证书文件路径，例如：/foo/alipayRootCert.crt -->";
        //注：如果采用非证书模式，则无需赋值上面的三个证书路径，改为赋值如下的支付宝公钥字符串即可
        config.alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlYB8rO37/hteLQqDcmF3xAREZd0gwk9wxsVOAgfj7r14YW016myzmnhI0v7hOyHoHwK9ilBRcVjn0oGDuDVEy9BER4EJyktBZ2y9jS5IDC+CQvAAHsp6ba12SYH0C0ekvD7tV0l/h0qQ0l5L2zhm5kHbNUkF0Q5cr7PTowy+Q/A1KjG3Izvb5DoCaiNKIfMq6wRqYBhxB135Oq3I+XOVTlrl6UBdjvYI0vn25HpWM71+LWIWSbRdILx1KEsk/081FVODzfbJKJ2dPhv9iXUPRvBUCiCmgX/OWNRWqKVnnW49A18AljbJ/XjXpOrN5BeQu8MLLd0ygcuZ3l0z8gXs6wIDAQAB";
        //可设置异步通知接收服务地址（可选）
//            config.notifyUrl = "https://www.baidu.com -->";
        //可设置AES密钥，调用AES加解密相关接口时需要（可选）
//            config.encryptKey = "<-- 请填写您的AES密钥，例如：aa4BtZ4tspm2wnXLb1ThQA== -->";
        return config;
    }
}
